<script>
  export default {
    name: "Header",
    data() {

      return {
        hRoute:null,
        cRoutes: null,
        activeIndex: ''// 默认激活的菜单
      }
    },
    methods: {
      handleSelect(key, keyPath) {

      }
    },
    beforeMount() {
      const matchedRoutes = this.$route.matched
      this.hRoute = matchedRoutes.at(0).path
      this.cRoutes = matchedRoutes.at(0).children
      this.activeIndex = matchedRoutes.at(1)?matchedRoutes.at(1).path : `${this.hRoute}/${this.cRoutes.at(0).path}`
      console.log(this.activeIndex)
    }
  }
</script>

<template>
  <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      @select="handleSelect"
      :router="true"
  >
    <el-menu-item v-for="cRoute in cRoutes" :key="cRoute.path" :index="hRoute+'/'+cRoute.path">{{ cRoute.meta.title }}</el-menu-item>

  </el-menu>
</template>

<style scoped>
.el-menu-demo {
  padding: 0;
}


</style>